package com.jv.popwindowlearning;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class DiyView extends androidx.appcompat.widget.AppCompatImageButton {
    boolean isZan = false;
    public DiyView(Context context) {
        super(context);
        setImageResource(R.drawable.unzan);
    }

    public DiyView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DiyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP) {
            if (!isZan) {
                setImageResource(R.drawable.zan);
                isZan = true;
            } else {
                setImageResource(R.drawable.unzan);
                isZan = false;
            }
            startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.zan));
        }
        return super.onTouchEvent(event);
    }
}
